
#import "SaveData.h"

// 宏定义, 直接根据文件名称, 拼接文件的绝对路径,
#define kFilePath(fileName) ([NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0] stringByAppendingPathComponent:fileName])

@implementation SaveData

#pragma mark
#pragma mark - 偏好设置保存
+ (void)saveValue:(NSString *)Value keyString:(NSString *)keyString {
    
    [[NSUserDefaults standardUserDefaults] setObject:Value forKey:keyString];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

#pragma mark
#pragma mark - 偏好设置读取
+ (NSString *)getKeyString:(NSString *)keyString {
    
    return [[NSUserDefaults standardUserDefaults] objectForKey:keyString];
}

#pragma mark
#pragma mark - plist文件保存

- (void)plistWritToFile:(NSString *)name content:(NSString*)content{
  
    NSString *filePath = kFilePath(name);
    
    [content writeToFile:filePath atomically:YES encoding:NSUTF8StringEncoding error:nil];

}

#pragma mark
#pragma mark - plist文件读取
- (NSString *)plistWritContent:(NSString *)name{

    return [NSString stringWithContentsOfFile:kFilePath(name) encoding:NSUTF8StringEncoding error:nil];
}

#pragma mark
#pragma mark - 归档
- (void)archiveData:(id)model feleName:(NSString *)name{

    [NSKeyedArchiver archiveRootObject:model toFile:kFilePath(name)];
}


#pragma mark
#pragma mark - 解归档
- (id)unarchivefileName:(NSString *)name{

    id model = [NSKeyedUnarchiver unarchiveObjectWithFile:name];
    return model;
}
@end
